using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AssetFrame.Message;
using System.Reflection;
using System.Data;
using MySql.Data.MySqlClient;
using SysFrame.Message;
using SysFrame.BP;

namespace AssetFrame.BP
{
    /// <summary>
    /// asset_a5方法
    /// </summary>
    public class MySQLasset_a5: Iasset_a5
    {

        /// <summary>
        /// 得到asset_a5实体
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns></returns>
        public List<Msasset_a5> Getasset_a5MsByQuery(MsQuery msq)
        {
            List<Msasset_a5> listms=new List<Msasset_a5>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            sb.Append("select asset_a5.* ");
            sb.Append(" from asset_a5 ");
            sb.Append(" where 1=1 ").Append(msq.strquery);
            if(msq.strorder != null && msq.strorder != "")
            {
				sb.Append(" order by ").Append(msq.strorder);
            }
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                DataSet ds = DbHelperMySQL.Query(lstCmdText[0].ToString());
               if (ds != null && ds.Tables.Count != 0 && ds.Tables[0].Rows.Count != 0)
                {
                	foreach(DataRow dr in ds.Tables[0].Rows)
                	{
                    	Msasset_a5 ms = new Msasset_a5();
                    	if(dr["ASSET_A5_AUTOID"].ToString()!=""){ms.ASSET_A5_AUTOID=int.Parse(dr["ASSET_A5_AUTOID"].ToString());}
                    	if(dr["ASSET_A5_ISDEL"]!=null && dr["ASSET_A5_ISDEL"].ToString()!=""){ms.ASSET_A5_ISDEL=dr["ASSET_A5_ISDEL"].ToString();}
                    	if(dr["ASSET_A5_MAKETIME"]!=null && dr["ASSET_A5_MAKETIME"].ToString()!=""){ms.ASSET_A5_MAKETIME=dr["ASSET_A5_MAKETIME"].ToString();}
                    	if(dr["ASSET_A5_MAKEUSER"]!=null && dr["ASSET_A5_MAKEUSER"].ToString()!=""){ms.ASSET_A5_MAKEUSER=dr["ASSET_A5_MAKEUSER"].ToString();}
                    	if(dr["ASSET_A5_PARENTID"]!=null && dr["ASSET_A5_PARENTID"].ToString()!=""){ms.ASSET_A5_PARENTID=dr["ASSET_A5_PARENTID"].ToString();}
                    	if(dr["ASSET_A5_MAKEFROM"]!=null && dr["ASSET_A5_MAKEFROM"].ToString()!=""){ms.ASSET_A5_MAKEFROM=dr["ASSET_A5_MAKEFROM"].ToString();}
                    	if(dr["ASSET_A5_10"]!=null && dr["ASSET_A5_10"].ToString()!=""){ms.ASSET_A5_10=dr["ASSET_A5_10"].ToString();}
                    	if(dr["ASSET_A5_20"]!=null && dr["ASSET_A5_20"].ToString()!=""){ms.ASSET_A5_20=dr["ASSET_A5_20"].ToString();}
                        if (dr["ASSET_A5_30"] != null && dr["ASSET_A5_30"].ToString() != "") { ms.ASSET_A5_30 = dr["ASSET_A5_30"].ToString(); }
                        if (dr["ASSET_A5_40"]!=null && dr["ASSET_A5_40"].ToString()!=""){ms.ASSET_A5_40=dr["ASSET_A5_40"].ToString();}
                    	if(dr["ASSET_A5_50"]!=null && dr["ASSET_A5_50"].ToString()!=""){ms.ASSET_A5_50=dr["ASSET_A5_50"].ToString();}
                    	if(dr["ASSET_A5_60"]!=null && dr["ASSET_A5_60"].ToString()!=""){ms.ASSET_A5_60=dr["ASSET_A5_60"].ToString();}
                    	if(dr["ASSET_A5_70"]!=null && dr["ASSET_A5_70"].ToString()!=""){ms.ASSET_A5_70=dr["ASSET_A5_70"].ToString();}
                    	listms.Add(ms);
                	}
                }
            }
            catch{}
            return listms;
        }

        /// <summary>
        ///  保存asset_a5信息
        /// </summary>
        /// <param name="ms">实体信息 通过ASSET_A5_AUTOID进行判断有ASSET_A5_AUTOID就是update</param>
        /// <returns>消息</returns>
        public MsReturned Saveasset_a5(Msasset_a5 ms)
        {
            MsReturned msr = new MsReturned();
            if(ms.ASSET_A5_AUTOID !=null && ms.ASSET_A5_AUTOID.ToString() !="" && ms.ASSET_A5_AUTOID.ToString() != "0")
            {
            	msr = Upasset_a5(ms);
            }
            else
            {
            	msr = Addasset_a5(ms);
            }
            return msr;
        }

        /// <summary>
        ///  新增asset_a5信息
        /// </summary>
        /// <param name="ms">实体信息 通过ASSET_A5_AUTOID进行判断有ASSET_A5_AUTOID就是update</param>
        /// <returns>消息</returns>
        public MsReturned Addasset_a5(Msasset_a5 ms)
        {
            List<string> lstResult = new List<string>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            MsReturned msr = new MsReturned();
            int newRateId = DataBase.GetMaxId("asset_a5", "ASSET_A5_AUTOID");
            sb.Append("insert into asset_a5 (");
            sb.Append("ASSET_A5_AUTOID,ASSET_A5_ISDEL,ASSET_A5_MAKETIME,ASSET_A5_MAKEUSER,ASSET_A5_PARENTID,");
            sb.Append("ASSET_A5_MAKEFROM,ASSET_A5_10,ASSET_A5_20,ASSET_A5_30,ASSET_A5_40,");
            sb.Append("ASSET_A5_50,ASSET_A5_60,ASSET_A5_70");
            sb.Append(")");
            sb.Append("values ( ");
            sb.Append(newRateId.ToString()).Append(",");
            sb.Append("@ASSET_A5_ISDEL,@ASSET_A5_MAKETIME,@ASSET_A5_MAKEUSER,@ASSET_A5_PARENTID,");
            sb.Append("@ASSET_A5_MAKEFROM,@ASSET_A5_10,@ASSET_A5_20,@ASSET_A5_30,@ASSET_A5_40,");
            sb.Append("@ASSET_A5_50,@ASSET_A5_60,@ASSET_A5_70)");
            MySqlParameter[] parameters = {
            		new MySqlParameter("@ASSET_A5_AUTOID", MySqlDbType.Int32,11),
            		new MySqlParameter("@ASSET_A5_ISDEL", MySqlDbType.VarChar,1),
            		new MySqlParameter("@ASSET_A5_MAKETIME", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A5_MAKEUSER", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A5_PARENTID", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A5_MAKEFROM", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A5_10", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A5_20", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A5_30", MySqlDbType.VarChar,100),
                    new MySqlParameter("@ASSET_A5_40", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A5_50", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A5_60", MySqlDbType.VarChar,100),
            		new MySqlParameter("@ASSET_A5_70", MySqlDbType.VarChar,100)};
            parameters[0].Value = ms.ASSET_A5_AUTOID;
            parameters[1].Value = ms.ASSET_A5_ISDEL;
            parameters[2].Value = ms.ASSET_A5_MAKETIME;
            parameters[3].Value = ms.ASSET_A5_MAKEUSER;
            parameters[4].Value = ms.ASSET_A5_PARENTID;
            parameters[5].Value = ms.ASSET_A5_MAKEFROM;
            parameters[6].Value = ms.ASSET_A5_10;
            parameters[7].Value = ms.ASSET_A5_20;
            parameters[8].Value = ms.ASSET_A5_30;
            parameters[9].Value = ms.ASSET_A5_40;
            parameters[10].Value = ms.ASSET_A5_50;
            parameters[11].Value = ms.ASSET_A5_60;
            parameters[12].Value = ms.ASSET_A5_70;
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(lstCmdText[0].ToString(),parameters);
                if (iexe > 0)
                {
                    msr.strMsId = newRateId.ToString();
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            lstCmdText = null;
            sb = null;
            return msr;
        }

        /// <summary>
        ///  更新asset_a5信息
        /// </summary>
        /// <param name="ms">实体信息 通过ASSET_A5_AUTOID进行判断有ASSET_A5_AUTOID就是update</param>
        /// <returns>消息</returns>
        public MsReturned Upasset_a5(Msasset_a5 ms)
        {
            List<string> lstResult = new List<string>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            MsReturned msr = new MsReturned();
           	sb.Append("update asset_a5 set ");
           	sb.Append(" ASSET_A5_AUTOID='").Append(ms.ASSET_A5_AUTOID).Append("' ");// ASSET_A5_AUTOID 
           	if (ms.ASSET_A5_ISDEL !=null && ms.ASSET_A5_ISDEL.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A5_ISDEL='").Append(ms.ASSET_A5_ISDEL).Append("' ");// ASSET_A5_ISDEL 是否删除
           	}
           	if (ms.ASSET_A5_MAKETIME !=null && ms.ASSET_A5_MAKETIME.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A5_MAKETIME='").Append(ms.ASSET_A5_MAKETIME).Append("' ");// ASSET_A5_MAKETIME 新增时间
           	}
           	if (ms.ASSET_A5_MAKEUSER !=null && ms.ASSET_A5_MAKEUSER.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A5_MAKEUSER='").Append(ms.ASSET_A5_MAKEUSER).Append("' ");// ASSET_A5_MAKEUSER 新增人
           	}
           	if (ms.ASSET_A5_PARENTID !=null && ms.ASSET_A5_PARENTID.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A5_PARENTID='").Append(ms.ASSET_A5_PARENTID).Append("' ");// ASSET_A5_PARENTID 上级ID
           	}
           	if (ms.ASSET_A5_MAKEFROM !=null && ms.ASSET_A5_MAKEFROM.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A5_MAKEFROM='").Append(ms.ASSET_A5_MAKEFROM).Append("' ");// ASSET_A5_MAKEFROM 来源
           	}
           	if (ms.ASSET_A5_10 !=null && ms.ASSET_A5_10.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A5_10='").Append(ms.ASSET_A5_10).Append("' ");// ASSET_A5_10 仓库名称
           	}
           	if (ms.ASSET_A5_20 !=null && ms.ASSET_A5_20.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A5_20='").Append(ms.ASSET_A5_20).Append("' ");// ASSET_A5_20 仓库编号
           	}
           	if (ms.ASSET_A5_30 !=null && ms.ASSET_A5_30.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A5_30='").Append(ms.ASSET_A5_30).Append("' ");// ASSET_A5_30 备用1
           	}
           	if (ms.ASSET_A5_40 !=null && ms.ASSET_A5_40.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A5_40='").Append(ms.ASSET_A5_40).Append("' ");// ASSET_A5_40 备用2
           	}
           	if (ms.ASSET_A5_50 !=null && ms.ASSET_A5_50.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A5_50='").Append(ms.ASSET_A5_50).Append("' ");// ASSET_A5_50 备用3
           	}
           	if (ms.ASSET_A5_60 !=null && ms.ASSET_A5_60.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A5_60='").Append(ms.ASSET_A5_60).Append("' ");// ASSET_A5_60 备用4
           	}
           	if (ms.ASSET_A5_70 !=null && ms.ASSET_A5_70.ToString() != ""){
           	    sb.Append(",").Append(" ASSET_A5_70='").Append(ms.ASSET_A5_70).Append("' ");// ASSET_A5_70 备用5
           	}
           	sb.Append(" where ASSET_A5_AUTOID='").Append(ms.ASSET_A5_AUTOID).Append("'");// ASSET_A5_AUTOID 
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(lstCmdText[0].ToString());
                if (iexe > 0)
                {
                    msr.strMsId = ms.ASSET_A5_AUTOID.ToString();
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            lstCmdText = null;
            sb = null;
            return msr;
        }

        /// <summary>
        /// 得到数据类型
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns>数据类型</returns>
        public MsReturned Getasset_a5ByQuery(MsQuery msq)
        {
        	DataSet ds = null;
        	MsReturned msr = new MsReturned();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            sb.Append("select asset_a5.* ");
            sb.Append(" from asset_a5 ");
            sb.Append(" where 1=1 ").Append(msq.strquery);
            if(msq.strorder!=null && msq.strorder != "")
            {
				sb.Append(" order by ").Append(msq.strorder);
            }
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                ds = DbHelperMySQL.Query(lstCmdText[0].ToString());
            }
            catch{}
            msr.data = ds;
            return msr;
        }

        /// <summary>
        /// 删除asset_a5
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns></returns>
        public MsReturned Deleteasset_a5ByQuery(MsQuery msq)
        {
            StringBuilder sb = new StringBuilder();
            MsReturned msr = new MsReturned();
            sb.Append(" delete from asset_a5 where ASSET_A5_AUTOID > 0 ").Append(msq.strquery);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(sb.ToString());
                if (iexe > 0)
                {
                    msr.strMsId = "1";
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            sb = null;
            return msr;
        }

    }
}
